package com.hsnn.medstgmini.pro.base.controller;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.model.DicSys;
import com.hsnn.medstgmini.base.dict.model.form.DicAreaForm;
import com.hsnn.medstgmini.base.dict.service.DicAreaManager;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.pro.base.model.BaseDelrelation;
import com.hsnn.medstgmini.pro.base.model.BaseGoods;
import com.hsnn.medstgmini.pro.base.model.form.BaseDelrelationForm;
import com.hsnn.medstgmini.pro.base.model.form.FileUploadResult;
import com.hsnn.medstgmini.pro.base.service.BaseGoodsManager;
import com.hsnn.medstgmini.sys.model.SysImportFileInfo;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.sys.service.SysImportFileInfoManager;
import com.hsnn.medstgmini.util.AreaUtil;
import com.hsnn.medstgmini.util.ConstantsUtil;
import com.hsnn.medstgmini.util.DicSysUtil;
import com.hsnn.medstgmini.util.FileUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.form.FileLoadForm;
/**
 * 
 *@category 商品管理
 *@author 邱磊
 *@date 2015年6月17日 下午8:53:15
 */
@Controller
@RequestMapping("/baseGoods")
public class BaseGoodsController {
	
	private static final Logger logger = LoggerFactory.getLogger(BaseGoodsController.class);
	
	@Autowired
	private BaseGoodsManager baseGoodsManager;
	@Autowired
	private  HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private SysImportFileInfoManager sfmanager;
	@Value("#{sysProp['system.uploadPath']}")
	private String uploadPath;
	@Value("#{sysProp['system.importGoodsPath']}")
	private String importGoodsPath;
	@Value("#{sysProp['system.importGoodsResultPath']}")
	private String importGoodsResultPath;
	@Value("#{sysProp['system.importGoodsMobanPath']}")
	private String importGoodsMobanPath;
	@Value("#{sysProp['system.importGoodsMoban']}")
	private String importGoodsMoban;
	@Value("#{sysProp['system.linxuan']}")
	private boolean linxuan;
	@Value("#{sysProp['system.delWithHosp']}")
	private boolean delWithHosp;
	@Autowired
	private HttpSession session;
	@Value("#{sysProp['system.gzfjydel']}")
	private String gzfjydel;//贵州非基药配送标识
	
	private SysUser getUser() {
		return (SysUser) session.getAttribute(Constants.USERINFO);
	}
	
	/**
	 * 
	 *@category 跳向列表页面
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:56:38
	 *@return
	 */
	@RequestMapping("/toList")
	public String toList(){
		List<DicSys> mlist = DicSysUtil.getDicListByClassCode(Constants.PRO_METHOD);
		request.setAttribute("list", mlist);
		return "/pro/base/baseGoodsList";
	}
	@RequestMapping("/toHaveSetDel")
	public String toHaveSetDel(){
		return "/pro/base/haveSetDel";
	}
	@RequestMapping("/toGoodsSelectComp")
	public String toGoodsSelectComp(){
		return "/pro/base/goodsSelectComp";
	}
	@RequestMapping("/getGoodsSelectComp")
	@ResponseBody
	public Pagination getGoodsSelectComp(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("areaId", request.getParameter("areaId"));
		page.getConditions().put("gzfjydel", gzfjydel);
		return baseGoodsManager.getGoodsSelectComp(page);
	}
	
	/**
	 * 
	 *@category 获取商品快快已设置的配送企业
	 *@author 邱磊
	 *@date 2015年12月21日 下午12:20:11
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getHaveSetDel")
	@ResponseBody
	public Pagination getHaveSetDel(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("gzfjydel", gzfjydel);
		return baseGoodsManager.getHaveSetDel(page);
	}
	/**
	 * 
	 *@category 删除商品的配送企业
	 *@author 邱磊
	 *@date 2015年12月21日 下午12:21:01
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/batchDeleteHaveSetDel")
	@ResponseBody
	public Pagination batchDeleteHaveSetDel(String array){
		Pagination page = new Pagination();
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<BaseDelrelationForm>>() {}.getType();
				List<BaseDelrelationForm> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					
//					for (BaseDelrelationForm dp : list) {
//						dp.setUpdUser(getUser().getId());
//						dp.setStatus(status);
//					}
					SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
					String goodsCode = request.getParameter("goodsCode");
					baseGoodsManager.batchDeleteHaveSetDel(goodsCode,list,user.getId());
					page.setSuccess(true);
					page.setMsg("删除成功！");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("删除失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 中心端新增配送关系
	 *@author 邱磊
	 *@date 2015年12月21日 下午4:16:57
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/setBaseDelRelation")
	@ResponseBody
	public Pagination setBaseDelRelation(String array){
		Pagination page = new Pagination();
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<BaseDelrelationForm>>() {}.getType();
				List<BaseDelrelationForm> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					String goodsCode = request.getParameter("goodsCode");
					SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
					baseGoodsManager.setBaseDelRelation(goodsCode,list,user.getId(),gzfjydel);
					page.setSuccess(true);
					page.setMsg("设置成功！");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("设置失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 跳转到商品列表页面
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:52:48
	 *@param form
	 *@return
	 */
	@RequestMapping("/getDataList")
	@ResponseBody
	public Pagination getDataList(BaseGoods form){
		Pagination page = new Pagination(request);
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		return page;
	}
	
	/**
	 * @category 卫生局查看商品目录
	 * @date 2015年11月16日
	 * @return
	 */
	@RequestMapping("/toGoodsListByWSJ")
	public String toGoodsListByWSJ(){
		return "/pro/base/catalog/goodsListByWSJ";
	}
	
	/**
	 * @category 卫生局查看商品目录
	 * @date 2015年11月16日
	 * @param form
	 * @return
	 */
	@RequestMapping("/getGoodsListByWSJ")
	@ResponseBody
	public Pagination getGoodsListByWSJ(BaseGoods form){
		Pagination page = new Pagination(request);
		page.setForm(form);
		page = baseGoodsManager.getGoodsListByWSJ(page, getUser());
		return page;
	}
	
	/**
	 * 
	 *@category 启用停用
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:53:29
	 *@param goodsCode 商品码
	 *@param status 1：启用，0：停用
	 *@return
	 */
	@RequestMapping("/switchStatus")
	@ResponseBody
	public Pagination switchStatus(String goodsCode,Short status){
		Pagination page = new Pagination(request);
		try {
			baseGoodsManager.switchStatus(goodsCode, status, getUser().getId());
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
		}
		return page;
	}
	/**
	 * 
	 *@category 批量启用停用
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:54:03
	 *@param array
	 *@return
	 */
	@RequestMapping("/batchSwitchStatus")
	@ResponseBody
	public Pagination batchSwitchStatus(String array,Short status){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<BaseGoods>>() {}.getType();
				List<BaseGoods> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					
					for (BaseGoods dp : list) {
						dp.setUpdUser(getUser().getId());
						dp.setStatus(status);
					}
					baseGoodsManager.batchSwitchStatus(list);
					page.setSuccess(true);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	/**
	 * 
	 *@category 跳转到新增页面
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:54:20
	 *@return
	 */
	@RequestMapping("/toAdd")
	public String toAdd(){
		return "/pro/base/baseGoodsAdd";
	}
	/**
	 * 
	 *@category 新增商品
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:54:37
	 *@param data
	 *@return
	 */
	@RequestMapping("/addData")
	@ResponseBody
	public Pagination addData(BaseGoods data){
		Pagination page = new Pagination(request);
		data.setUpdDatetime(new Date());
		data.setStatus(Short.valueOf("1"));
		try {
			baseGoodsManager.addData(data);
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
		}
		return page;
	}
	/**
	 * 
	 *@category 上传导入商品文件，并校验商品文件
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:54:52
	 *@param goodFile
	 *@return
	 */
	@RequestMapping("/bathImportView")
	@ResponseBody
	public Pagination bathImportView(@RequestParam(value="goodFile",required=false) MultipartFile goodFile ){
		Pagination page = new Pagination();
		FileUploadResult result = null;
		try {
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
			page.setForm(user);
			page.getConditions().put(Constants.PROJID, request.getParameter(Constants.PROJID));
			result = baseGoodsManager.uploadFile(goodFile, page);
			String fileId = result.getFileId();
			if (StringUtils.isBlank(fileId)){
				page.setSuccess(false);
				page.setMsg(result.getResult());
				return page;
			}
			CheckGoodsThread th = new CheckGoodsThread(fileId, baseGoodsManager, user);
			th.start();
			page.setSuccess(true);
			page.setMsg(result.getResult());
			return page;
		} catch (Exception e) {
			logger.error("文件上传失败：", e);
			page.setSuccess(false);
			page.setMsg(result.getResult());
			return page;
		}
	}
	
	
	
	
	
	
	/**
	 * 
	 *@category 批量导入
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:55:31
	 *@param validList 有效数据List
	 *@return
	 */
	@RequestMapping("/bathImport")
	@ResponseBody
	public Pagination bathImport(String validList){
		Pagination page = new Pagination();
		List<BaseGoods> list = new Gson().fromJson(validList, new TypeToken<List<BaseGoods>>(){}.getType());
		try {
			baseGoodsManager.bathImport(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	/**
	 * 
	 *@category 跳向生产企业设置商品配送关系列表页面
	 *@author 邱磊
	 *@date 2015年6月17日 上午10:58:57
	 *@return
	 */
	@RequestMapping("/toProDelDrugList")
	public String toProDelDrugList(){
		if (delWithHosp){
			Pagination page = new Pagination();
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
			String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
			page.getConditions().put("compCode", compCode);
			request.setAttribute("isDelrelation", baseGoodsManager.isDelrelation(page));
			return "/pro/base/projDrugList"; 
		}
		return "/pro/base/baseGoodsDelList";
	}
	/**
	 * 
	 *@category 获取生产企业设置商品配送关系列表
	 *@author 邱磊
	 *@date 2015年6月17日 上午11:04:22
	 *@return
	 */
	@RequestMapping("/getProDelDrugDataList")
	@ResponseBody
	public Pagination getProDelDrugDataList(){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("projId", request.getParameter("projId"));
		page = baseGoodsManager.getProDelDrugDataList(page);
		return page;
	}
	@Autowired
	private DicAreaManager dicAreaManager;
	@Value("#{sysProp['system.province']}")
    private String province;
	/**
	 * 
	 *@category 跳向根据区域设置配送企业页面
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:21:40
	 *@return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toBaseGoodsDelByArea")
	public String toBaseGoodsDelByArea(){
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		request.setAttribute("goodsArea", request.getParameter("goodsArea"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/baseGoodsDelByArea";
	}
	/**
	 * 
	 *@category 根据区域设置配送企业列表
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:22:16
	 *@return
	 */
	@RequestMapping("/getBaseGoodsDelByAreaList")
	@ResponseBody
	public Pagination getBaseGoodsDelByAreaList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("projID", request.getParameter("projID"));
		page.getConditions().put("areaId", request.getParameter("areaId"));
		if(linxuan){
			return baseGoodsManager.getBaseGoodsDelByLinxuan(page);
		}
		return baseGoodsManager.getBaseGoodsDelByAreaList(page);
	}
	/**
	 * 
	 *@category 根据区域设置配送企业
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:58:22
	 *@return
	 */
	@RequestMapping("/setDelByArea")
	@ResponseBody
	public Pagination setDelByArea(String array,String areaCode,String goodsCode){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<BaseDelrelation>>() {
				}.getType();
				List<BaseDelrelation> list = gson.fromJson(array, type);
				Map<String, String> map = new HashMap<String, String>();
				map.put("areaCode", request.getParameter("areaCode"));
				map.put("goodsCode", request.getParameter("goodsCode"));
				SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
				map.put("userId", user.getId());
				baseGoodsManager.setDelByArea(list, map);
				page.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 根据区域设置配送企业
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:58:22
	 *@return
	 */
	@RequestMapping("/setDelByComp")
	@ResponseBody
	public Pagination setDelByComp(String array,String goodsCode){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<BaseDelrelation>>() {
				}.getType();
				List<BaseDelrelation> list = gson.fromJson(array, type);
				Map<String, String> map = new HashMap<String, String>();
				SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
				map.put("userId", user.getId());
				baseGoodsManager.setDelByComp(list,map);
				page.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 跳向根据企业设置配送区域
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:21:40
	 *@return
	 */
	@RequestMapping("/toBaseGoodsDelByComp")
	public String toBaseGoodsDelByComp(){
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		return "/pro/base/baseGoodsDelByComp";
	}
	/**
	 * 
	 *@category 根据企业设置配送区域的区域
	 *@author 邱磊
	 *@date 2015年6月17日 下午8:55:56
	 *@return
	 */
	@RequestMapping("/getAreaDataList" )
	@ResponseBody
	public Pagination getDataInfo(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("goodsArea", request.getParameter("goodsArea"));
		return baseGoodsManager.getAreaList(page);
	}
	/**
	 * 
	 *@category 跳向按区域设置配送关系（选择配送企业）
	 *@author 邱磊
	 *@date 2015年6月30日 下午5:09:17
	 *@return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toDelCompSelect" )
	public String toDelCompSelect(String areaId, String areaName){
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		request.setAttribute("areaName", areaName);
		return "/pro/base/baseGoodsDelSelComp";
	}
	/**
	 * 
	 *@category 查看配送关系（生产企业）
	 *@author 邱磊
	 *@date 2015年6月18日 上午8:30:56
	 *@return
	 */
	@RequestMapping("/toBaseDelrelationList" )
	public String toBaseDelrelationList(){
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/baseDelByCompList";
	}
	/**
	 * 
	 *@category 查询当前生产企业的所有药品配送关系
	 *@author 邱磊
	 *@date 2015年6月18日 上午9:58:25
	 *@return
	 */
	@RequestMapping("/getBaseDelByCompList" )
	@ResponseBody
	public Pagination getBaseDelByCompList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("projName", request.getParameter("projName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		String areaCode = AreaUtil.getAreaStartCode(province, request.getParameter("area2"), request.getParameter("area3"));
		page.getConditions().put("areaCode",areaCode);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page = baseGoodsManager.getBaseDelByCompList(page);
		return page;
	}
	/**
	 * 
	 *@category 查看配送关系日志
	 *@author 邱磊
	 *@date 2015年6月18日 上午8:30:56
	 *@return
	 */
	@RequestMapping("/toBaseDelLogList" )
	public String toBaseDelLogList(){
		request.setAttribute("delRelId", request.getParameter("delRelId"));
		return "/pro/base/baseDelLogList";
	}
	/**
	 * 
	 *@category 根据商品查看配送关系
	 *@author 邱磊
	 *@date 2015年6月25日 下午1:14:11
	 *@return
	 */
	@RequestMapping("/toBaseDelByGoods" )
	public String toBaseDelByGoods(){
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		return "/pro/base/baseDelByGoods";
	}
	/**
	 * 
	 *@category 查询配送关系日志列表
	 *@author 邱磊
	 *@date 2015年6月18日 上午9:58:25
	 *@return
	 */
	@RequestMapping("/getBaseDelByCompLogList" )
	@ResponseBody
	public Pagination getBaseDelByCompLogList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("endDate", request.getParameter("endDate"));
		page.getConditions().put("startDate", request.getParameter("startDate"));
		page.getConditions().put("delRelId", request.getParameter("delRelId"));
		page = baseGoodsManager.getBaseDelByCompLogList(page);
		return page;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/toSetDelComp" )
	public String toSetDelComp(){
		try {
			request.setAttribute("areaName", URLDecoder.decode(request.getParameter("areaName"), "utf-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		return "/pro/base/compSetDel";
	}
	@RequestMapping("/getSetDelComp" )
	@ResponseBody
	public Pagination getSetDelComp(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("status", request.getParameter("status"));
		page = baseGoodsManager.getSetDelComp(page);
		return page;
	}
	/**
	 * 
	 *@category 解除、拒绝配送关系
	 *@author 邱磊 
	 *@date 2015年11月21日13:30:21 应晓川
	 *@param array
	 *@return
	 */
	@RequestMapping("/removeDel" )
	@ResponseBody
	public Pagination removeDel(String param,String status){
		Pagination page = new Pagination();
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		try {
			page.getConditions().put("userId", user.getId());
			page.getConditions().put("param", param);
			page.getConditions().put("status", status);
			baseGoodsManager.removeDel(page);
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
			page.setMsg("申报失败！");
		}
		return  page;
	}
	/**
	 * 
	 *@category 查看商品在某区域设置的配送关系日志
	 *@author 邱磊
	 *@date 2015年7月2日 上午9:16:58
	 *@return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toDelLogByAreaList" )
	public String toDelLogByAreaList(){
		try {
			String areaName = request.getParameter("areaName");
			areaName = new String(areaName.getBytes("ISO8859-1"),"utf-8");
			request.setAttribute("areaName", areaName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		return "/pro/base/delLogByAreaList";
	}
	/**
	 * 
	 *@category 获取配送关系日志
	 *@author 邱磊
	 *@date 2015年7月2日 上午9:13:19
	 *@return
	 */
	@RequestMapping("/getBaseDelerationLogList" )
	@ResponseBody
	public Pagination getBaseDelerationLogList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("startDate", request.getParameter("startDate"));
		page.getConditions().put("endDate", request.getParameter("endDate"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		return baseGoodsManager.getBaseDelerationLogList(page);
	}
	/**
	 * 
	 *@category 跳向按企业设置配送区域
	 *@author 邱磊
	 *@date 2015年7月2日 上午11:02:57
	 *@return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toSetDelByComp" )
	public String toSetDelByComp(){
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		return "/pro/base/baseGoodsDelByComp";
	}
	/**
	 * 
	 *@category 获取按配送企业设置配送区域的配送企业列表
	 *@author 邱磊
	 *@date 2015年7月2日 上午11:52:25
	 *@return
	 */
	@RequestMapping("/getDelComp" )
	@ResponseBody
	public Pagination getDelComp(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("projId", request.getParameter("projID"));
		page.getConditions().put("areaCode", request.getParameter("goodsArea"));
		if(linxuan) {
			return baseGoodsManager.getDelCompByLinxuan(page);
		}
		return baseGoodsManager.getDelComp(page);
	}
	/**
	 * 
	 *@category 跳向按配送企业设置配送区域的配送区域列表页面
	 *@author 邱磊
	 *@date 2015年7月2日 下午1:58:51
	 *@return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toDelArea" )
	public String toDelArea(){
		String compName = request.getParameter("compName");
		String compCode = request.getParameter("compCode");
		request.setAttribute("compCode", compCode);
		request.setAttribute("compName", compName);
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/delArea";
	}
	/**
	 * 
	 *@category 获取按配送企业设置配送区域的配送区域列表数据
	 *@author 邱磊
	 *@date 2015年7月2日 下午1:59:38
	 *@return
	 */
	@RequestMapping("/getDelArea" )
	@ResponseBody
	public Pagination getDelArea(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("goodsArea", request.getParameter("goodsArea"));
		if(linxuan){
			return baseGoodsManager.getDelAreaByLinxuan(page);
		}
		return baseGoodsManager.getDelArea(page);
	}
	@SuppressWarnings("unchecked")
	@RequestMapping("/toSetDelArea" )
	public String toSetDelArea(){
		try {
			String compName = request.getParameter("compName");
			request.setAttribute("compName", compName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		request.setAttribute("compCode", request.getParameter("compCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/areaSetDel";
	}
	@RequestMapping("/getSetDelArea" )
	@ResponseBody
	public Pagination getSetDelArea(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("status", request.getParameter("status"));
		return baseGoodsManager.getSetDelArea(page);
	}
	@SuppressWarnings("unchecked")
	@RequestMapping("/toDelLogByCompList" )
	public String toDelLogByCompList(){
		try {
			String compName = request.getParameter("compName");
			String compCode = request.getParameter("compCode");
			compName = new String(compName.getBytes("ISO8859-1"),"utf-8");
			request.setAttribute("compName", compName);
			request.setAttribute("compCode", compCode);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/areaSetDelLog";
	}
	@RequestMapping("/getSetDelAreaLog" )
	@ResponseBody
	public Pagination getSetDelAreaLog(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("startDate", request.getParameter("startDate"));
		page.getConditions().put("endDate", request.getParameter("endDate"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		return baseGoodsManager.getSetDelAreaLog(page);
	}
	/**
	 * 
	 *@category 跳向导入商品文件列表页面
	 *@author 邱磊
	 *@date 2015年11月11日 下午6:33:28
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toImportFileList" )
	public String toImportFileList(){
		request.setAttribute("fileStatus", ConstantsUtil.importFileStatus);
		return "/pro/base/baseGoodsImportList";
	}
	/**
	 * 
	 *@category 获取商品导入文件列表
	 *@author 邱磊
	 *@date 2015年11月11日 下午6:34:06
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getImportFileDataList")
	@ResponseBody
	public Pagination getImportFileDataList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("projId", request.getParameter("projId"));
		page.getConditions().put("fileName", request.getParameter("fileName"));
		page.getConditions().put("starttime", request.getParameter("starttime"));
		page.getConditions().put("endtime", request.getParameter("endtime"));
		page.getConditions().put("status", request.getParameter("status"));
		page.getConditions().put("filetype", "1");
		page = baseGoodsManager.getImportFileDataList(page);
		return page;
	}
	@RequestMapping("/toImoprtGoodsView")
	public String toImoprtGoodsView(){
		request.setAttribute(Constants.FILEID, request.getParameter(Constants.FILEID));
		return "/pro/base/baseGoodsImportView";
	}
	/**
	 * 
	 *@category 获取预览列表
	 *@author 邱磊
	 *@date 2015年11月12日 上午8:32:59
	 *@param
	 */
	@RequestMapping("/getImportGoodsView")
	@ResponseBody
	public Pagination getImportGoodsView(){
		Pagination page = new Pagination();
		page.getConditions().put(Constants.FILEID, request.getParameter(Constants.FILEID));
		page = baseGoodsManager.getImportGoodsView(page);
		return page;
	}
	/**
	 * 
	 *@category 预览时导入验证成功的商品
	 *@author 邱磊
	 *@date 2015年11月12日 上午10:38:47
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/importGoods")
	@ResponseBody
	public Pagination importGoods(){
		Pagination page = new Pagination();
		try {
			int flag = baseGoodsManager.importGoods(request.getParameter("fileId"));
			page.setSuccess(true);
			page.setMsg("成功导入" + flag + "条商品！");
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("导入失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 预览时放弃导入
	 *@author 邱磊
	 *@date 2015年11月12日 上午10:58:54
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/deleteImportGoods")
	@ResponseBody
	public Pagination deleteImportGoods(){
		Pagination page = new Pagination();
		try {
			baseGoodsManager.deleteImportGoods(request.getParameter("fileId"));
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("放弃失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 下载结果
	 *@author 邱磊
	 *@date 2015年11月12日 上午11:20:38
	 *@param 
	 *@return ResponseEntity<byte[]>
	 */
	@RequestMapping("/downloadResult")    
    public void downloadResult() throws Exception {  
		SysImportFileInfo map = sfmanager.getImportFileById(request.getParameter("fileId"));
		FileLoadForm form = new FileLoadForm();
		form.setRequest(request);
		form.setResponse(response);
		form.setFilePath(uploadPath + importGoodsResultPath);
		form.setFileName(map.getFileName());
		FileUtil.downLoad(form);
	}
	
	
	
	/**
	 * 
	 *@category 模板下载
	 *@author 邱磊
	 *@date 2015年11月12日 上午11:20:38
	 *@param 
	 *@return ResponseEntity<byte[]>
	 */
	@RequestMapping("/downloadModel")    
    public void downloadModel() throws Exception {  
		FileLoadForm form = new FileLoadForm();
		form.setRequest(request);
		form.setResponse(response);
		form.setFilePath(importGoodsMobanPath);
		form.setFileName(importGoodsMoban);
		FileUtil.downLoad(form);
	}
	/**
	 * 
	 *@category 预览导入时校验是否有重复导入
	 *@author 邱磊
	 *@date 2015年11月17日 下午2:20:06
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/checkReImport")    
	@ResponseBody
	public Pagination checkReImport(){
		Pagination page = new Pagination();
		page.getConditions().put(Constants.FILEID, request.getParameter("fileId"));
		page = baseGoodsManager.checkReImport(page);
		if (StringUtils.isBlank(page.getMsg())){
			page.setMsg("");
		}
		return page;
	}
	
	/**
	 * 
	 *@category 跳向配送关系查看列表页面(生产企业)
	 *@author 应晓川
	 *@date 2015年11月23日17:54:49
	 *@return
	 */
	@RequestMapping("/toProjDrugList")
	public String toProjDrugList(){
		Pagination page = new Pagination();
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		request.setAttribute("isDelrelation", baseGoodsManager.isDelrelation(page));
		return "/pro/base/projDrugList";
	}
	
	/**
	 * 
	 *@category 获取配送关系列表(生产企业)
	 *@author 应晓川
	 *@date 2015年11月23日17:54:41
	 *@return
	 */
	@RequestMapping("/getProjDrugList")
	@ResponseBody
	public Pagination getProjDrugList(String delCompName,String hospName){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		if(StringUtils.isNotBlank(delCompName)){
			page.getConditions().put("delCompName",delCompName);
		}
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName",hospName);
		}
		page = baseGoodsManager.getProjDrugList(page);
		return page;
	}
	
	/**
	 * 
	 *@category  配送关系:跳向医疗机构列表 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toHospList")
	public String toHospList(){
		return "/pro/base/hospList";
	}
	@RequestMapping("/getHospList")
	@ResponseBody
	public Pagination getHospList(String hospName,String hospCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName",hospName);
		}
		if(StringUtils.isNotBlank(hospCode)){
			page.getConditions().put("hospCode",hospCode);
		}
		page = baseGoodsManager.getHospList(page);
		return page;
	}
	
	
	/**
	 * 
	 *@category  配送关系:跳向配送企业列表 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toDelCompList")
	public String toDelCompList(){
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		request.setAttribute("prodCompCode", compCode);
		return "/pro/base/delCompList";
	}
	@RequestMapping("/getDelCompList")
	@ResponseBody
	public Pagination getDelCompList(String delCompName){
		Pagination page = new Pagination(request);
	
	    if(linxuan){
	    	if(StringUtils.isNotBlank(delCompName)){
				page.getConditions().put("compName",delCompName);
			}
	    	return baseGoodsManager.getDelCompListByLinxuan(page);
		}else{
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
			String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
			page.getConditions().put("compCode", compCode);
			if(StringUtils.isNotBlank(delCompName)){
				page.getConditions().put("delCompName",delCompName);
			}
			return baseGoodsManager.getDelCompList(page);	
		}
		
	}
	
	/**
	 * 
	 *@category  配送关系:跳向按配送企业设置医疗机构
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toTheDelCompList")
	public String toTheDelCompList(){
		try {
			request.setAttribute("compName", new String(request.getParameter("compName").getBytes("iso8859-1"),"utf-8"));
		} catch (UnsupportedEncodingException e) {
			logger.error("企业名称编码转换：" , e);
		}
		return "/pro/base/theDelCompList";
	}
	
	/**
	 * 
	 *@category  获取配送企业列表
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/getTheDelCompList")
	@ResponseBody
	public Pagination getTheDelCompList(){
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("compCode", request.getParameter("compCode"));
			page.getConditions().put("compName", request.getParameter("compName"));
			if(linxuan){
				baseGoodsManager.getTheDelCompListByLinxuan(page);
			}else{
				baseGoodsManager.getTheDelCompList(page);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
	
	/**
	 * 
	 *@category  配送关系:跳向已设置医疗机构
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toDelRelationHospList")
	public String toDelRelationHospList(){
		try {
			request.setAttribute("compName", new String(request.getParameter("compName").getBytes("iso8859-1"),"utf-8"));
			request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
			DicAreaForm area = dicAreaManager.getDicAreaById(province);
			request.setAttribute("area", area);
		} catch (UnsupportedEncodingException e) {
			logger.error("企业名称转换：", e);
		}
		return "/pro/base/delRelationHospList";
	}
	
	/**
	 * 
	 *@category  获取已设置医疗机构列表
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/getDelRelationHospList")
	@ResponseBody
	public Pagination getDelRelationHospList(){
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("delCompCode", request.getParameter("delCompCode"));
			page.getConditions().put("prodCompCode", request.getParameter("prodCompCode"));
			page.getConditions().put("hospCode", request.getParameter("hospCode"));
			page.getConditions().put("hospName", request.getParameter("hospName"));
			page.getConditions().put("areaCode", AreaUtil.getAreaStartCode(request.getParameter("area1"), request.getParameter("area2"), request.getParameter("area3")));
			baseGoodsManager.getDelRelationHospList(page);
		} catch (Exception e) {
			logger.error("获取已置医疗机构配送关系：", e);
		}
		return page;
	}
	

	/**
	 * 
	 *@category  配送关系:跳向设置日志页面
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toDelRelationHospLog")
	public String toDelRelationHospLog(){
		try {
			request.setAttribute("compName", new String(request.getParameter("compName").getBytes("iso8859-1"),"utf-8"));
			DicAreaForm area = dicAreaManager.getDicAreaById(province);
			request.setAttribute("area", area);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "/pro/base/delRelationHospLog";
	}
	
	/**
	 * 
	 *@category  配送关系:跳向设置操作页面
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/toSetDelRelationHosp")
	public String toSetDelRelationHosp(){
		request.setAttribute("compName", request.getParameter("compName"));
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/setDelRelationHosp";
	}
	
	/**
	 * 
	 *@category  获取未设置医疗机构列表
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/getNoSetDelRelHospList")
	@ResponseBody
	public Pagination getNoSetDelRelHospList(){
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("delCompCode", request.getParameter("delCompCode"));
			page.getConditions().put("hospCode", request.getParameter("hospCode"));
			page.getConditions().put("hospName", request.getParameter("hospName"));
			page.getConditions().put("areaCode", AreaUtil.getAreaStartCode(request.getParameter("area1"), request.getParameter("area2"), request.getParameter("area3")));
			if(linxuan){
				baseGoodsManager.getNoSetDelRelHospListByLinxuan(page);
			}else{
				baseGoodsManager.getNoSetDelRelHospList(page);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}

	/////////////////////////////以上OK/////////////////////////////////////////////////////	
	/**
	 * 
	 *@category  按配送企业选择医疗机构 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日10:58:52
	 *@return
	 */
	@RequestMapping("/toDelHospJsp")
	public String toDelHospJsp(String compCode,String compName){
		request.setAttribute("compCode", compCode);
		request.setAttribute("compName", compName);
		return "/pro/base/delHospJsp";
	}
	@RequestMapping("/getDelHospJspList")
	@ResponseBody
	public Pagination getDelHospJspList(String hospName,String hospCode,String delCompCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page.getConditions().put("delCompCode", delCompCode);
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName",hospName);
		}
		if(StringUtils.isNotBlank(hospCode)){
			page.getConditions().put("hospCode",hospCode);
		}
		page = baseGoodsManager.getDelHospJspList(page);
		return page;
	}
	/**
	 * 
	 *@category  按配送企业查已选择的医疗机构 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日10:58:52
	 *@return
	 */
	@RequestMapping("/toHospJsp")
	public String toHospJsp(String compCode,String compName){
		request.setAttribute("compCode", compCode);
		request.setAttribute("compName", compName);
		return "/pro/base/hospJsp";
	}
	@RequestMapping("/getHospJspList")
	@ResponseBody
	public Pagination getHospJspList(String delCompCode, String hospName,String hospCode,String status){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page.getConditions().put("delCompCode", delCompCode);
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName",hospName);
		}
		if(StringUtils.isNotBlank(hospCode)){
			page.getConditions().put("hospCode",hospCode);
		}
		if(StringUtils.isNotBlank(status)){
			page.getConditions().put("status",status);
		}
		page = baseGoodsManager.getHospJspList(page);
		return page;
	}
	//////////////////////分割///////////////////////////////////
	/**
	 * 
	 *@category  按医疗机构选择配送企业 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日10:58:52
	 *@return
	 */
	@RequestMapping("/toDelCompJsp")
	public String toDelCompJsp(String hospCode,String hospName){
		request.setAttribute("hospName", hospName);
		request.setAttribute("hospCode", hospCode);
		return "/pro/base/delCompJsp";
	}
	@RequestMapping("/getDelCompJspList")
	@ResponseBody
	public Pagination getDelCompJspList(String compName,String compCode,String hospCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String proCompCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", proCompCode);
		page.getConditions().put("hospCode", hospCode);
		if(StringUtils.isNotBlank(compName)){
			page.getConditions().put("delCompName",compName);
		}
		if(StringUtils.isNotBlank(compName)){
			page.getConditions().put("delCompName",compName);
		}
		page = baseGoodsManager.getDelCompJspList(page);
		return page;
	}
	/**
	 * 
	 *@category  按医疗机构查看已选择的配送企业 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日10:58:52
	 *@return
	 */
	@RequestMapping("/toCompJsp")
	public String toCompJsp(String hospCode,String hospName){
		request.setAttribute("hospName", hospName);
		request.setAttribute("hospCode", hospCode);
		return "/pro/base/compJsp";
	}
	@RequestMapping("/getCompJspList")
	@ResponseBody
	public Pagination getCompJspList(String compName,String compCode,String status,String hospCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String proCompCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", proCompCode);
		page.getConditions().put("hospCode", hospCode);
		if(StringUtils.isNotBlank(compName)){
			page.getConditions().put("delCompName",compName);
		}
		if(StringUtils.isNotBlank(compCode)){
			page.getConditions().put("delCompCode",compCode);
		}
		if(StringUtils.isNotBlank(status)){
			page.getConditions().put("status",status);
		}
		page = baseGoodsManager.getCompJspList(page);
		return page;
	}
	
	/**
	 * 
	 *@category  按配送企业设置医疗机构 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日16:51:28
	 *@return
	 */
	@RequestMapping("/setDelWithHosp")
	@ResponseBody
	public Pagination setDelWithHosp(String hospCode,String delCompCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		StdCompinfo sc = (StdCompinfo )user.getInfo();
		page.setForm(sc);
		try {
			if (StringUtils.isNotBlank(hospCode) && StringUtils.isNotBlank(delCompCode)) {
				page.getConditions().put("userId", user.getId());
				page.getConditions().put("hospCodes", hospCode);
				page.getConditions().put("delCompCode", delCompCode);
				baseGoodsManager.setDelWithHosp(page);
				page.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category  按医疗机构设置配送企业 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月24日16:51:28
	 *@return
	 */
	@RequestMapping("/setDelWithComp")
	@ResponseBody
	public Pagination setDelWithComp(String delCompCode,String hospCode){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		StdCompinfo sc = (StdCompinfo )user.getInfo();
		page.setForm(sc);
		try {
			if (StringUtils.isNotBlank(hospCode) && StringUtils.isNotBlank(delCompCode)) {
				page.getConditions().put("userId", user.getId());
				page.getConditions().put("hospCode", hospCode);
				page.getConditions().put("delCompCodes", delCompCode);
				baseGoodsManager.setDelWithComp(page);
				page.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	
	
	
	/**
	 * 
	 *@category  获取配送企业设置医疗机构日志列表
	 *@author wangbing
	 *@date 2015年11月23日19:49:40
	 *@return
	 */
	@RequestMapping("/getDelRelationHospLog")
	@ResponseBody
	public Pagination getDelRelationHospLog(){
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("delCompCode", request.getParameter("delCompCode"));
			page.getConditions().put("prodCompCode", request.getParameter("prodCompCode"));
			page.getConditions().put("hospCode", request.getParameter("hospCode"));
			page.getConditions().put("hospName", request.getParameter("hospName"));
			page.getConditions().put("areaCode", AreaUtil.getAreaStartCode(request.getParameter("area1"), request.getParameter("area2"), request.getParameter("area3")));
			baseGoodsManager.getDelRelationHospLog(page);
		} catch (Exception e) {
			logger.error("获取配送企业设置医疗机构日志列表", e);
		}
		return page;
	}
	
	/**
	 * 
	 *@category 根据配送企业设置医疗机构
	 *@author wangbing
	 *@date 2015年6月17日 下午4:58:22
	 *@return
	 */
	@RequestMapping("/setHospByDelComp")
	@ResponseBody
	public Pagination setHospByDelComp(String array){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<Map<String,String>>>() {
				}.getType();
				List<Map<String,String>> list = gson.fromJson(array, type);
				SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
				String updUser = user.getId();
				page.setOperCount(baseGoodsManager.setHospByDelComp(list, updUser));
				page.setSuccess(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	
	
	/**
	 * 
	 *@category  查看配送医疗机构日志 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月25日10:39:48
	 *@return
	 */
	@RequestMapping("/toDelRelHospLog")
	public String toDelRelHospLog(String delCompCode,String delCompName){
		request.setAttribute("delCompCode", delCompCode);
		try {
			delCompName =new String(delCompName.getBytes("iso8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("delCompName", delCompName);
		return "/pro/base/delRelHospLog";
	}
	@RequestMapping("/getDelRelHospLog")
	@ResponseBody
	public Pagination getDelRelHospLog(String delCompCode,String hospCode,String hospName){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String proCompCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", proCompCode);
		page.getConditions().put("delCompCode", delCompCode);
		if(StringUtils.isNotBlank(hospCode)){
			page.getConditions().put("hospCode", hospCode);
		}
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName",hospName);
		}
		page = baseGoodsManager.getDelRelHospLog(page);
		return page;
	}
	
	/**
	 * 
	 *@category  查看配送企业日志 (生产企业)
	 *@author 应晓川
	 *@date 2015年11月25日10:56:49
	 *@return
	 */
	@RequestMapping("/toDelRelCompLog")
	public String toDelRelCompLog(String hospName,String hospCode){
		try {
			hospName =new String(hospName.getBytes("iso8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("hospCode", hospCode);
		request.setAttribute("hospName", hospName);
		return "/pro/base/delRelCompLog";
	}
	@RequestMapping("/getDelRelCompLog")
	@ResponseBody
	public Pagination getDelRelCompLog(String hospCode,String delCompCode,String delCompName){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String proCompCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", proCompCode);
		page.getConditions().put("hospCode", hospCode);
		if(StringUtils.isNotBlank(delCompCode)){
			page.getConditions().put("delCompCode", delCompCode);
		}
		if(StringUtils.isNotBlank(delCompName)){
			page.getConditions().put("delCompName",delCompName);
		}
		page = baseGoodsManager.getDelRelCompLog(page);
		return page;
	}
	
}

class CheckGoodsThread extends Thread{
	private String fileId;
	private BaseGoodsManager manager;
	private SysUser user;
	public CheckGoodsThread(String fileId, BaseGoodsManager manager,SysUser user){
		this.fileId = fileId;
		this.manager = manager;
		this.user = user;
	}
	public void run (){
		try {
			manager.bathImport(fileId, user);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}